package oldFiles;
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;

public class SimpleLightReader implements SimpleSensor {
	
	SensorPort sp;
	
	private static int MINLIGHT = 500;
	private static int MAXLIGHT = 600;
	
	public SimpleLightReader(SensorPort sp) {
		this.sp = sp;
	}
	
	@Override
	public int readValue() {
		
		int rawValue = sp.readRawValue();
		
		//LCD.drawString("LightBefore: "+rawValue, 0, 0);
		int returnValue = normalize(rawValue); 
		//LCD.drawString("Light: "+returnValue, 0, 1);
		return returnValue;
	}
	
	private int normalize(int value) {
		
		if (value > 1000) {value=1000;}
		value = 1000-value;
		
		if (value>MAXLIGHT) {value = MAXLIGHT;}
		if (value<MINLIGHT) {value = MINLIGHT;}
		value = value - MINLIGHT;
		return value * 10;
	}

}
